package com.shunhao.mvp

import android.os.Bundle
import android.view.View
import com.shunhao.base.BaseFragment

/**
 * <pre>
 * 文件名：	MvpBaseFragment
 * 时　间：	2018/3/14 15:38
 * @author 康贵阳
</pre> *
 */
abstract class BaseMvpFragment<P : BasePresenter<Any>?> : BaseFragment() {

    var mPresenter: P? = null

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

        mPresenter = createPresenter()
        mPresenter?.attachView(this)
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()

        //presenter断开与界面的联系
        mPresenter?.detachView()
    }

    /**
     * 创建Presenter
     *
     * @return
     */
    protected abstract fun createPresenter(): P?
}